package util;

import android.app.Application;
import android.graphics.Bitmap;
import android.os.Environment;

import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiscCache;
import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.nostra13.universalimageloader.cache.memory.impl.UsingFreqLimitedMemoryCache;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;
import com.parkcar.R;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.WXAPIFactory;
import java.io.File;

/**
 * Created by Administrator on 2016/1/23.
 */
public class CarApplication extends Application{
    private File filename,filename1;
    @Override
    public void onCreate() {
        super.onCreate();
        if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
            filename = new File(getApplicationContext().getExternalCacheDir().getPath() + "/car_images"); //	storage/emulated/0/Android/data/com.qts.customer/cache
            filename1 = new File(getApplicationContext().getExternalCacheDir().getPath() + "/car_images1");
        } else {
            filename = new File(getApplicationContext().getCacheDir().getPath() + "/qtscustomer_images"); //  data/data/Cache/qtscustomer_images
            filename1 = new File(getApplicationContext().getCacheDir().getPath() + "/qtscustomer_images1");// data/data/Cache/qtscustomer_images1
        }
        DisplayImageOptions displayImageOptions = new DisplayImageOptions.Builder()
                .cacheInMemory(true)
                .cacheOnDisk(true)
                .showImageForEmptyUri(R.drawable.ic_launcher) // 设置图片Uri为空或是错误的时候显示的图片
                .bitmapConfig(Bitmap.Config.RGB_565)
                .imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2).build();

        ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
                getApplicationContext())
                .defaultDisplayImageOptions(displayImageOptions)
                .threadPoolSize(3).threadPriority(Thread.NORM_PRIORITY - 2)
                .memoryCache(new UsingFreqLimitedMemoryCache(15 * 1024 * 1024))
                .denyCacheImageMultipleSizesInMemory()
                .diskCache(new UnlimitedDiscCache(filename, filename1, new Md5FileNameGenerator()))
                .tasksProcessingOrder(QueueProcessingType.LIFO)
                .build();
        ImageLoader.getInstance().init(config);
        final IWXAPI msgApi = WXAPIFactory.createWXAPI(getApplicationContext(), null);

        // 将该app注册到微信
        msgApi.registerApp("wxac2843ffa600c3d2");
    }
}
